<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>入库确认</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- ① 极简 CSS 框架 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@1/css/pico.min.css">
    <script src="/js/axios.min.js"></script>
    <style>
        body{ display:flex; align-items:center; justify-content:center; min-height:100vh; background:#f5f7fa; }
        .card{ max-width:400px; width:100%; padding:2rem; border-radius:8px; box-shadow:0 4px 12px rgba(0,0,0,.1); }
        h2{ text-align:center; margin-bottom:1.2rem; }
        .info-line{ margin:.4rem 0; }
        .btn-full{ width:100%; margin-top:1rem; }
    </style>
</head>
<body>
<div class="card">
    <h2>入库信息确认</h2>
    <div id="info"></div>
    <button class="btn-full primary" onclick="confirmStockIn()">确认入库</button>
</div>

<script>
    const inputId = new URLSearchParams(location.search).get('inputId');
    if (!inputId) { alert('缺少参数 inputId'); window.close(); }

    axios.get(`/productInput/mobile/${inputId}`)
        .then(res => {
            const d = res.data.data;
            document.getElementById('info').innerHTML = `
          <div class="info-line"><strong>领料单号：</strong>${d.requisitionId}</div>
          <div class="info-line"><strong>商品名称：</strong>${d.productName}</div>
          <div class="info-line"><strong>入库数量：</strong>${d.num} ${d.unitName}</div>
          <div class="info-line"><strong>仓库：</strong>${d.warehouseName}</div>
        `;
        })
        .catch(() => { alert('获取信息失败'); });

    function confirmStockIn() {
        axios.put('/productInput/confirm', { inputId })
            .then(res => {
                if (res.data.code === 200) {
                    alert('入库成功！');
                    /* ② 跳回上一页 / 列表页 */
                    window.location.replace(document.referrer || 'about:blank');
                } else {
                    alert('入库失败：' + res.data.msg);
                }
            })
            .catch(() => { alert('网络错误，请重试'); });
    }
</script>
</body>
</html>